package com.dragon.client.controller.contract;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.contract.IEquipmentService;
import com.dragon.repository.domain.dto.EquipmentDTO;
import com.dragon.repository.domain.vo.EquipmentVO;
import com.dragon.repository.entity.Equipment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 设备 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-11-29
 */
@RestController
@RequestMapping("equipment")
@Api(tags = "设备")
public class EquipmentController {

    @Autowired
    IEquipmentService service;

    @GetMapping("list")
    @ApiOperation(value = "设备列表")
    public ResponseData<List<EquipmentDTO>> equipmentList(@ApiParam(name = "type", value= "状态", required = false, type = "int")
                                                          @RequestParam(required = false) Integer type){
        List<Equipment> equipments = service.equipmentList(type);
        return ResponseData.success(EquipmentDTO.convertList(equipments));
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseData equipmentAdd(@RequestBody @Validated(Insert.class) EquipmentVO vo){
        service.equipmentAdd(EquipmentVO.convert(vo));
        return ResponseData.success();
    }


    @PostMapping("update")
    @ApiOperation(value = "修改")
    public ResponseData equipmentUpdate(@RequestBody @Validated(Update.class) EquipmentVO vo){
        service.equipmentUpdate(EquipmentVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("enter")
    @ApiOperation(value = "录入数据")
    public ResponseData enterDate(@RequestBody @Validated(Insert.class) EquipmentVO vo){
        service.enterData(EquipmentVO.convert(vo));
        return ResponseData.success();
    }

}
